<?php
namespace Admin\Controller;


class LinkController extends CommonController
{

    private $link;

    public function __construct()
    {
        parent::__construct();
        $this->link = M('link');
    }

    public function index()
    {
        $links = $this->link->order('sort_order')->select();
        $this->assign('links', $links);
        $this->display();
    }

    public function store()
    {
        $this->link->create();
        $this->link->add();
        $this->success('新增成功');
    }

    public function destroy()
    {
        $id = I('get.id');
        $this->link->delete($id);
        $this->success('删除成功');
    }


    public function update()
    {
//        dump($_POST);
        $this->link->create();
        $this->link->save();
        $this->success('编辑成功');
    }


    public function destroy_checked()
    {
        $delete_id = I('post.delete_id');

        foreach ($delete_id as $id) {
            $this->link->delete($id);
        }

        $this->success('删除成功');
    }

    public function sort_order()
    {
        $sort_order = I("post.sort_order");
        $id = I("post.id");

        foreach ($id as $key => $value) {
            $this->link->where("id=$value")->setField('sort_order', $sort_order[$key]);
        }
        $this->redirect('index');
    }
}